// preload.js
const { contextBridge } = require('electron');

// 导入拆分的模块
const moduleHelpers = require('./preload/moduleHelpers');
const reactHelpers = require('./preload/reactHelpers');
const electronAPI = require('./preload/electronAPI');

// 暴露第三方库模块到渲染进程
contextBridge.exposeInMainWorld('module', moduleHelpers);

// 暴露 React 相关 API 到渲染进程
contextBridge.exposeInMainWorld('reactHelpers', reactHelpers);

// 暴露 Electron API 到渲染进程
contextBridge.exposeInMainWorld('electronAPI', electronAPI);

window.addEventListener('DOMContentLoaded', () => {
  const replaceText = (selector, text) => {
    const element = document.getElementById(selector)
    if (element) element.innerText = text
  }

  for (const dependency of ['chrome', 'node', 'electron']) {
    replaceText(`${dependency}-version`, process.versions[dependency])
  }
})
